package com.xiaoma.myaudience.biz.adapter;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.xiaoma.myaudience.R;
import com.xiaoma.myaudience.biz.view.LoadingImageView;
import com.xiaoma.myaudience.util.PicUtils;

public class CategorySearchAdapter extends CursorAdapter {

	private LayoutInflater mInflater;

	private Context mContext;
	
	private String mSizeStr;

	public CategorySearchAdapter(Context context, Cursor c, boolean autoRequery) {
		super(context, c, autoRequery);

		mInflater = LayoutInflater.from(context);
		mContext = context;
		
		mSizeStr = PicUtils.composeSize((int) context.getResources().getDimension(
                R.dimen.list_item_img_width), (int) context.getResources().getDimension(
                R.dimen.list_item_img_height));
	}

	@Override
	public void bindView(View view, Context context, Cursor cursor) {
//		ViewHolder holder = (ViewHolder) view.getTag();
//
//		final String title = cursor.getString(CategoryListActivity.INDEX_TITLE);
//		final String pid = cursor.getString(CategoryListActivity.INDEX_PID);
//
//		holder.img.setLoadingDrawable(cursor.getString(CategoryListActivity.INDEX_IMG), mSizeStr);
//		holder.title.setText(title);
//		holder.launch.setText(context.getResources().getString(
//				R.string.video_launch,cursor.getString(CategoryListActivity.INDEX_LAUNCH)));
//		holder.performer.setText(context.getResources().getString(
//				R.string.video_performer,
//				cursor.getString(CategoryListActivity.INDEX_PERFORMER)));
//		holder.type.setText(context.getResources().getString(
//				R.string.video_type,
//				cursor.getString(CategoryListActivity.INDEX_TYPE)));
//		holder.play.setOnClickListener(new OnClickListener() {
//
//			@Override
//			public void onClick(View v) {
//				// TODO Auto-generated method stub
//				Intent intent = new Intent(mContext, PlayActivity.class);
//				PlayVideoInfo playInfo = new PlayVideoInfo();
//				playInfo.mPid = pid;
//				playInfo.mTitle = title;
//				playInfo.mUrlList = null;
//				Bundle b = new Bundle();
//				b.putParcelable("playInfo", playInfo);
//				intent.putExtras(b);
//				mContext.startActivity(intent);
//			}
//
//		});
	}

	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent) {
		View convertView = mInflater.inflate(R.layout.video_list_item, null);
		ViewHolder holder = new ViewHolder();
		holder.img = (LoadingImageView) convertView.findViewById(R.id.img);
		holder.title = (TextView) convertView.findViewById(R.id.title);
//		holder.launch = (TextView) convertView.findViewById(R.id.launch);
//		holder.performer = (TextView) convertView.findViewById(R.id.performer);
//		holder.type = (TextView) convertView.findViewById(R.id.type);
		holder.play = (ImageView) convertView.findViewById(R.id.play);
		convertView.setTag(holder);
		return convertView;
	}

    private class ViewHolder {
        LoadingImageView img;

        TextView title;
        
        TextView launch;
        
        TextView performer;
        
        TextView type;
        
        ImageView play;
    }

}
